//===================================================================
// 项目名 : Hbt.Cur
// 文件名 : HbtDbSeedUser.cs
// 创建者 : Claude
// 创建时间: 2024-02-19
// 版本号 : V0.0.1
// 描述   : 用户数据提供类
//===================================================================

using Hbt.Common.Options;
using Hbt.Common.Utils;
using Hbt.Domain.Entities.Identity;
using Microsoft.Extensions.Options;

namespace Hbt.Infrastructure.Data.Seeds;

/// <summary>
/// 用户数据提供类
/// </summary>
public class HbtDbSeedUser
{
    private readonly IOptions<HbtPasswordPolicyOptions> _passwordPolicyOptions;

    /// <summary>
    /// 构造函数
    /// </summary>
    /// <param name="passwordPolicyOptions">密码策略配置选项</param>
    public HbtDbSeedUser(IOptions<HbtPasswordPolicyOptions> passwordPolicyOptions)
    {
        _passwordPolicyOptions = passwordPolicyOptions ?? throw new ArgumentNullException(nameof(passwordPolicyOptions));
    }

    /// <summary>
    /// 获取默认用户数据
    /// </summary>
    /// <returns>用户数据列表</returns>
    public List<HbtUser> GetDefaultUsers()
    {
        var users = new List<HbtUser>();

        // 使用配置中的默认密码创建哈希值
        var (adminHash, adminSalt, adminIterations) = HbtPasswordUtils.CreateHash(_passwordPolicyOptions.Value.DefaultPassword);
        var (developerHash, developerSalt, developerIterations) = HbtPasswordUtils.CreateHash(_passwordPolicyOptions.Value.DefaultPassword);
        var (testerHash, testerSalt, testerIterations) = HbtPasswordUtils.CreateHash(_passwordPolicyOptions.Value.DefaultPassword);
        var (userHash, userSalt, userIterations) = HbtPasswordUtils.CreateHash(_passwordPolicyOptions.Value.DefaultPassword);
        var (demoHash, demoSalt, demoIterations) = HbtPasswordUtils.CreateHash(_passwordPolicyOptions.Value.DefaultPassword);

        users.Add(new HbtUser
        {
            UserName = "admin",
            NickName = "超级管理员",
            RealName = "超级管理员",
            FullName = "超级管理员",
            EnglishName = "System Administrator",
            UserType = 2,
            Email = "admin@hbt365.net",
            PhoneNumber = "13800000001",
            Gender = 0,
            Avatar = "/avatar/default.gif",
            UserStatus = 0,
            IsLock = 0,
            ErrorLimit = 0,
            LoginCount = 0,
            Password = adminHash,
            Salt = adminSalt,
            Iterations = adminIterations
        });

        users.Add(new HbtUser
        {
            UserName = "developer",
            NickName = "开发工程师",
            RealName = "开发工程师",
            FullName = "开发工程师",
            EnglishName = "Developer",
            UserType = 1,
            Email = "developer@lean.com",
            PhoneNumber = "13800000002",
            Gender = 0,
            Avatar = "/avatar/default.gif",
            UserStatus = 0,
            IsLock = 0,
            ErrorLimit = 0,
            LoginCount = 0,
            Password = developerHash,
            Salt = developerSalt,
            Iterations = developerIterations
        });

        users.Add(new HbtUser
        {
            UserName = "tester",
            NickName = "测试工程师",
            RealName = "测试工程师",
            FullName = "测试工程师",
            EnglishName = "Test Engineer",
            UserType = 1,
            Email = "tester@lean.com",
            PhoneNumber = "13800000003",
            Gender = 0,
            Avatar = "/avatar/default.gif",
            UserStatus = 0,
            IsLock = 0,
            ErrorLimit = 0,
            LoginCount = 0,
            Password = testerHash,
            Salt = testerSalt,
            Iterations = testerIterations
        });

        users.Add(new HbtUser
        {
            UserName = "user",
            NickName = "普通用户",
            RealName = "普通用户",
            FullName = "普通用户",
            EnglishName = "Normal User",
            UserType = 1,
            Email = "user@lean.com",
            PhoneNumber = "13800000004",
            Gender = 0,
            Avatar = "/avatar/default.gif",
            UserStatus = 0,
            IsLock = 0,
            ErrorLimit = 0,
            LoginCount = 0,
            Password = userHash,
            Salt = userSalt,
            Iterations = userIterations
        });

        users.Add(new HbtUser
        {
            UserName = "demo",
            NickName = "演示用户",
            RealName = "演示用户",
            FullName = "演示用户",
            EnglishName = "Demo User",
            UserType = 1,
            Email = "demo@lean.com",
            PhoneNumber = "13800000005",
            Gender = 0,
            Avatar = "/avatar/default.gif",
            UserStatus = 0,
            IsLock = 0,
            ErrorLimit = 0,
            LoginCount = 0,
            Password = demoHash,
            Salt = demoSalt,
            Iterations = demoIterations
        });

        return users;
    }
}